package com.mytomcat.catalina.container;

import com.mytomcat.catalina.valve.StandardWrapperValve;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 标准Wrapper
 *
 * @author supu
 * @date 2019-04-19 17:04
 **/
public class StandardWrapper extends ContainerBase {
    private static final Logger LOGGER = LoggerFactory.getLogger(StandardWrapper.class);

    private static Map<String,String> servletNameMap;

    public StandardWrapper() {
        pipeline.setBasic(new StandardWrapperValve());

        if(servletNameMap == null){
            servletNameMap = new HashMap<>(2);
        }
    }

    @Override
    protected void startInternal() {
        LOGGER.info("StandardWrapper start");

        super.startInternal();

        // 初始化
        init();
    }

    @Override
    protected void stopInternal() {
        LOGGER.info("StandardWrapper stop");
    }

    @Override
    protected void destroyInternal() {
        LOGGER.info("StandardWrapper destroy");
    }

    public Map<String, String> getServletNameMap() {
        return servletNameMap;
    }

    private void init(){
        // init servletNameMap
        servletNameMap.put("default", "com.mytomcat.catalina.servlet.DefaultServlet");
        servletNameMap.put("jsp", "com.mytomcat.catalina.servlet.JspServlet");
    }
}
